/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.objects;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Content object
 * @author Kyle Parker, University Computing Services
 */
public class Content implements Comparable<Content> {
	private String categoryID;
	private String categoryName;
	private String contentID;
	private URL fullStoryURL;
	private String headline;
	private String tagline;
	private URL thumbURL;

	public String getCategoryID() {		
		return categoryID;
	}
	public void setCategoryID(String value) {
		this.categoryID = value.trim();
	}
	
	public String getCategoryName() {		
		return categoryName;
	}
	public void setCategoryName(String value) {
		this.categoryName = value.trim();
	}
	
	public String getContentID() {		
		return contentID;
	}
	public void setContentID(String value) {
		this.contentID = value.trim();
	}
	
	public URL getFullStoryURL() {
		return fullStoryURL;
	}	
	public void setFullStoryURL(String value) {
		try  {
			this.fullStoryURL = new URL(value);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}
	
	public String getHeadline() {		
		return headline;
	}
	public void setHeadline(String value) {
		this.headline = value.trim();
	}
	
	public String getTagline() {		
		return tagline;
	}
	public void setTagline(String value) {
		this.tagline = value.trim();
	}
	
	public URL getThumbURL() {
		return thumbURL;
	}	
	public void setThumbURL(String value) {
		try  {
			this.thumbURL = new URL(value);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}
    
	public Content copy() {
		Content copy = new Content();
		copy.categoryID = categoryID;
		copy.categoryName = categoryName;
		copy.contentID = contentID;
		copy.fullStoryURL = fullStoryURL;
		copy.headline = headline;
		copy.tagline = tagline;
		copy.thumbURL = thumbURL;
		return copy;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + ((categoryID == null) ? 0 : categoryID.hashCode());
		result = prime * result + ((categoryName == null) ? 0 : categoryName.hashCode());
		result = prime * result + ((contentID == null) ? 0 : contentID.hashCode());
		result = prime * result + ((fullStoryURL == null) ? 0 : fullStoryURL.hashCode());
		result = prime * result + ((headline == null) ? 0 : headline.hashCode());
		result = prime * result + ((tagline == null) ? 0 : tagline.hashCode());
		result = prime * result + ((thumbURL == null) ? 0 : thumbURL.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		
		if (obj == null) return false;
		
		if (getClass() != obj.getClass()) return false;
		
		Content other = (Content) obj;

		if (categoryID == null) {
			if (other.categoryID != null) return false;
		} else if (!categoryID.equals(other.categoryID)) return false;

		if (categoryName == null) {
			if (other.categoryName != null) return false;
		} else if (!categoryName.equals(other.categoryName)) return false;

		if (contentID == null) {
			if (other.contentID != null) return false;
		} else if (!contentID.equals(other.contentID)) return false;

		if (fullStoryURL == null) {
			if (other.fullStoryURL != null) return false;
		} else if (!fullStoryURL.equals(other.fullStoryURL)) return false;

		if (headline == null) {
			if (other.headline != null) return false;
		} else if (!headline.equals(other.headline)) return false;

		if (tagline == null) {
			if (other.tagline != null) return false;
		} else if (!tagline.equals(other.tagline)) return false;

		if (thumbURL == null) {
			if (other.thumbURL != null) return false;
		} else if (!thumbURL.equals(other.thumbURL)) return false;
		
		return true;
	}
	
	public int compareTo(Content another) {
		if (another == null) return 1;
		return another.categoryID.compareTo(categoryID);
	}
}
